home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DIMISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-19
|
6KB
|
175 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dimisc.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// NOTE: Data File also added to module Z4SDBLD with 1 line of code
// added to fix a problem with this module. This is the only
// module that needed the fix to the library was left with the
// original code. The fix does cause a suspisios pointer
// conversion but that is ok as it is fine.
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains support routines for data files.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Check if a file is a valid data file.
// Parameters: pcsz File name
// Returns: TRUE if valid data file.
//----------------------------------------------------------------------------
BOOL FN_E DioIsDataFile(PCSZ pcsz, PCSZ pcszAppId)
{
CHAR szName[MAX_PATH];
USHORT fs = FL_OPEN|FL_BINARY|FL_READONLY|FL_DENYNONE;
HF hf;
FPOS fsize;
DATAHDR hdr;
//
// Create full name of file and verify existence.
//
Assert(pcsz && pcsz[0]);
strcpy(szName, pcsz);
FnameAppendExt(szName, di.szDataExt, TRUE);
if (!FnameQualify(szName, di.szDataExt, di.pcszDataPath, FNAME_NO_CREATE))
return FALSE;
if (!FileOpen(&hf, szName, fs, NULL))
return FALSE;
//
// Go to great extents to verify that this is an actual
// and uncorrupted data file. This is the only place that the
// header data is verified. Directory entries are verified as
// they are read.
//
fsize = FileGetSize(hf);
if (fsize < sizeof(DATAHDR)
|| (fsize % sizeof(DATAHDR)) != 0)
{
FileClose(hf);
return FALSE;
}
if (!FileRead(hf, (PBYTE)&hdr, sizeof(DATAHDR), 0L))
{
FileClose(hf);
return FALSE;
}
FileClose(hf);
strcpy((PSZ)pcszAppId,"ZIP4");
if (hdr.lId != DFH_ID
|| hdr.usVersion < DFH_VERION
|| hdr.crc != (ULONG)CrcCalc((PBYTE)&hdr, sizeof(DATAHDR) - sizeof(ULONG)))
return FALSE;
if (pcszAppId && memcmp(hdr.szAppId, pcszAppId, sizeof(hdr.szAppId)) != 0)
return FALSE;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Check if file pointer is at end of file.
// Parameters: hlf Logical file handle
// Returns: TRUE if at EOF
//----------------------------------------------------------------------------
BOOL FN_E DioIsEof(HLF hlf)
{
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
return (di.logical[hlf].fl & LF_EOF) != 0;
}
//----------------------------------------------------------------------------
// Description: Check if file is in error state.
// Parameters: hlf Logical file handle
// Returns: TRUE if file is in an error state
//----------------------------------------------------------------------------
BOOL FN_E DioIsError(HLF hlf)
{
HPF hpf;
if (hlf < 0 || hlf >= MAX_LOGICAL_FILES || !di.logical[hlf].fUsed)
return TRUE;
hpf = di.logical[hlf].hpf;
return (di.logical[hlf].fl & LF_ERROR) || (di.physical[hpf].fl & PF_ERROR);
}
//----------------------------------------------------------------------------
// Description: Check if file is a valid logical file.
// Parameters: pcsz Logical file name.
// This name may contain an explicit phyiscal file
// name by placing it prior to the logical name
// and separating it using the tilde character:
// "physical~logical"
// usType File type to open.
// Returns: TRUE if logical file name is valid
//----------------------------------------------------------------------------
BOOL FN_E DioIsLogicalFile(PCSZ pcsz, USHORT usType)
{
HPF hpf;
SIZET cDir;
DATADIR dir;
// Find logical file
return DioFindLogical(pcsz, usType, &hpf, &cDir, &dir);
}
//----------------------------------------------------------------------------
// Description: Check if file pointer is valid
// Parameters: hlf Logical file handle
// Returns: TRUE if at valid
//----------------------------------------------------------------------------
BOOL FN_E DioIsValid(HLF hlf)
{
return hlf >= 0
&& hlf < MAX_LOGICAL_FILES
&& di.logical[hlf].fUsed
&& (di.logical[hlf].fl & LF_ERROR) == 0
&& (di.physical[di.logical[hlf].hpf].fl & PF_ERROR) == 0;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------